package com.sl.au.repository;

import java.util.Date;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.sl.au.entity.VisitorReward;

public interface VisitorRewardRepository extends JpaRepository<VisitorReward, String> {
	@Query("select v from VisitorReward v where v.user.id=?1 and (v.user.name like %?2% or v.user.sex like %?2% or v.register.registerEventName like %?2%)")
	Page<VisitorReward> findRewardByKeyAndCon(Pageable pageable, String key, String con);

	@Query("select v from VisitorReward v where v.user.id=?1")
	Page<VisitorReward> findRewardOnlyKey(Pageable pageable, String key);

	@Query("select v from VisitorReward v where v.register.id=?1")
	VisitorReward findByEventRegister(String registerId);
	
	@Modifying
	@Query("delete VisitorReward a where a.register.id = ?1")
	int deleteReward(String registerId);
	
	@Query("select v from VisitorReward v where v.user.id=?1 and v.createTime > ?2 and v.createTime <?3 order by v.createTime desc")
	List<VisitorReward> getUserRewardListByDate(String userId, Date begin, Date end);

	@Query("select v from VisitorReward v where v.user.id=?1 order by v.createTime desc")
	List<VisitorReward> getUserRewardAll(String userId);
}
